<template>
  <div class="main">
    <div class="title">
      <span>拜访登记</span>
    </div>
    <div class="info">
      <van-field
        v-model="data.PersonnelName"
        label="姓名:"
        type="input"
        required
      />
      <van-field v-model="data.Phone" label="电话:" type="input" required />
      <van-field v-model="data.Address" label="当前居住地:" type="input" required/>
      <van-field v-model="data.AccessTool" label="车牌号:" type="input" required/>
      <van-field
        v-model="data.VisitorsUnit"
        label="来访人员所属单位:"
        type="input"
        required
      />
	  <eagle-input
        name="VisitUnit"
        label="拜访单位"
        v-model="data.VisitUnit.CompanyName"
        required
        :islink="true"
        readonly
        @click="CountryName()"
        placeholder="请选择拜访单位"
      ></eagle-input>
      <!-- <van-field v-model="data.VisitUnit" label="拜访单位:" type="input" /> -->
      <van-field v-model="data.Visitor" label="拜访人员:" type="input" required/>
      <van-field
        v-model="data.VisitorPhone"
        label="拜访人员联系方式:"
        type="input"
        required
      />

      <eagle-date-picker
      v-model="data.BeginTime"
      label="开始时间"
      is-link
      input-align="right"
      required
      @change="examStartChange"
      :minDate="startMinDate"
    ></eagle-date-picker>
    <eagle-date-picker
      v-model="data.EndTime"
      label="结束时间"
      is-link
      input-align="right"
      required
      :minDate="endMinDate"
    ></eagle-date-picker>
      <!-- <eagle-date
        label="结束日期"
        :date.sync="data.EndTime"
        required
        placeholder="点击选择日期"
      ></eagle-date> -->
      <van-field v-model="data.Reason" label="拜访事由:" type="input" required/>

    </div>

    <check-type-dialog
      v-model="show"
      :data="data"
      @close="closeCountry"
    ></check-type-dialog>
  
    <div class="bottom_submit">
      <van-button class="button" type="primary" @click="_submit()"
        >确 定</van-button
      >
    </div>
  </div>
</template>

<script>
import checkTypeDialog from "@/views/yq/access/checkTypeDialog.vue";
import DateTimePicker from "../../../components/DateTimePicker.vue";
export default {
  components: {
    checkTypeDialog,
    DateTimePicker,
  },
  data() {
    return {
      data: {
        Name: "",
        Mobile: "",
        VisitUnit: {},
        VisitUnitList: [
      //     { CompanyCode: "茶山村", CompanyName: "茶山村" },
      //     { CompanyCode: "茶山圩", CompanyName: "茶山圩" },
      //     { CompanyCode: "下朗村", CompanyName: "下朗村" },
      //     { CompanyCode: "横江村", CompanyName: "横江村" },
      //     { CompanyCode: "京山村", CompanyName: "京山村" },
		  // {
      //       CompanyCode: "148208",
      //       CompanyNo: null,
      //       CompanyName: "众安测试公司1" 
      //   }
        ],
      },
      show: false,
    };
  },
  created() {
    this._LoadVisitUnitList();
  },

  methods: {
    _submit() {
      if (this.data.PersonnelName == null || this.data.PersonnelName == "") {
        return this.$toast("请输入姓名");
      } else if (this.data.Phone == null || this.data.Phone == "") {
        return this.$toast("请输入电话");
      } else if (this.data.Address == null || this.data.Address == "") {
        return this.$toast("请输入当前居住地");
      } else if (this.data.AccessTool == null || this.data.AccessTool == "") {
        return this.$toast("请输入到访工具");
      } else if (
        this.data.VisitorsUnit == null ||
        this.data.VisitorsUnit == ""
      ) {
        return this.$toast("请输入来访人员所属单位");
      } else if (this.data.VisitUnit.CompanyName == null || this.data.VisitUnit.CompanyName == "") {
        return this.$toast("请输入拜访单位");
      } else if (this.data.Visitor == null || this.data.Visitor == "") {
        return this.$toast("请输入拜访人员名称");
      } else if (
        this.data.VisitorPhone == null ||
        this.data.VisitorPhone == ""
      ) {
        return this.$toast("请输入拜访人员电话");
      } else if (this.data.BeginTime == null || this.data.BeginTime == "") {
        return this.$toast("请输入拜访开始时间");
      } else if (this.data.EndTime == null || this.data.EndTime == "") {
        return this.$toast("请输入拜访结束时间");
      } else if (this.data.Reason == null || this.data.Reason == "") {
        return this.$toast("请输入拜访事由");
      }
      console.log(this.data);
      this.$axios.post(

        // path: "/chsReport/FirstType",
       "/PersonnelAccess/AddorUpdate",
      {
          // Info: this.data,
			  PersonnelName:this.data.PersonnelName,
		  Phone:this.data.Phone,
		  Address:this.data.Address,
      AccessTool:this.data.AccessTool,
		  VisitorsUnit:this.data.VisitorsUnit,
		  VisitUnit:this.data.VisitUnit.CompanyCode,
      VisitUnitName:this.data.VisitUnit.CompanyName,
		  Visitor:this.data.Visitor,
		  VisitorPhone:this.data.VisitorPhone,
		  BeginTime:this.data.BeginTime,
		  EndTime:this.data.EndTime,
		  Reason:this.data.Reason
        },
      ).then((res)=>{
        console.log(res)
        if(res.success){
          this.$toast.success("新增成功!")
          this.$router.goRefresh(-1);
        }
      });
    },
    _LoadVisitUnitList() {
      var self = this;
      this.$axios
        .get("/PersonnelAccess/GetEnterpriseDrop",{params:{CompanyCode:this.$route.query.CompanyCode}})
        .then((res) => {
          self.data.VisitUnitList = res.data;
          console.log(self.VisitUnitList);
        });

    },
    CountryName() {
      this.show = true;
    },
    // 关闭弹框
    closeCountry(type) {
      if (type) {
        this.data.VisitUnit = type;
      }
      this.show = false;
    },
    examStartChange(val){
      this.endMinDate = new Date(this.$moment(val).format("YYYY/MM/DD HH:mm:ss"))
    }
  },
};
</script>

<style lang="less" scoped>
.title {
  height: 30px;
  font-size: 20px;
  text-align: center;
  margin-top: 15px;
  margin-bottom: 15px;
}
.van-field__label {
  -webkit-box-flex: 0;
  -webkit-flex: none;
  flex: none;
  box-sizing: border-box;
  width: 50px;
  margin-right: 0.32rem;
  color: #646566;
  text-align: left;
  word-wrap: break-word;
}
.info {
  margin-left: 5px;
  margin-right: 5px;
  border-radius: 20px;
}
.bottom_submit {
  width: 100%;
  margin-top: 10px;
  text-align: center;
}
.button {
  width: 98%;
}
</style>
